<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>

<f:message var="headline" key="global.searchResults"/>

<c:if test="${pageContext.request.isUserInRole('ROLE_ADMIN')}" >
    <s:layout-render name="/content.jsp" nadpis="${headline}">
        <s:layout-component name="telo">
            <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" var="actionBean"/>
            <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.SkillsActionBean" var="skillsBean"/>
            <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.HousesActionBean" var="housesBean"/>

            <c:choose>
                <c:when test="${! actionBean.ghostsWithName.isEmpty()}">
                    <table class="zakladni">
                        <tr>
                            <th class=""><f:message key="ghosts.id"/></th>
                            <th><f:message key="ghosts.name"/></th>
                            <th><f:message key="ghosts.hauntingFrom"/></th>
                            <th><f:message key="ghosts.hauntingTo"/></th>
                            <th><f:message key="ghosts.power"/></th>
                            <th><f:message key="ghosts.skill"/></th>
                            <th><f:message key="ghosts.house"/></th>
                            <th><f:message key="ghosts.description"/></th>                
                        </tr>
                        <c:forEach items="${actionBean.ghostsWithName}" var="ghost">
                            <tr>
                                <td>${ghost.id}</td>
                                <td><c:out value="${ghost.name}"/></td>
                                <td><c:out value="${ghost.hauntingFrom}"/></td>
                                <td><c:out value="${ghost.hauntingTo}"/></td>
                                <td><c:out value="${ghost.power}"/>%</td>
                                <td><c:out value="${ghost.skill.name}"/></td>
                                <td><c:out value="${ghost.house.name}"/></td>
                                <td><c:out value="${ghost.description}"/></td>
                                <c:if test="${pageContext.request.isUserInRole('ROLE_ADMIN')}" >
                                    <td class="edit"><s:link beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" event="delete" ><s:param name="ghost.id" value="${ghost.id}"/><f:message key="ghosts.delete"/></s:link> </td>
                                    <td class="edit"><s:link beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" event="edit" ><s:param name="ghost.id" value="${ghost.id}"/><f:message key="ghosts.edit"/></s:link> </td>
                                </c:if>
                            </tr>
                        </c:forEach>
                    </table>
                </c:when>
                <c:otherwise>
                    <f:message key="global.noResults"/>
                </c:otherwise>
            </c:choose>



            <s:form beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean">
                <s:submit name="all" class="button"><f:message key="global.showAll"/></s:submit>
            </s:form>
        </s:layout-component>
    </s:layout-render>
</c:if>